home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Tutorial / Cookbook / 32.Math / rand.c < prev   
C/C++ Source or Header  |  1995-06-12  |  295b  |  17 lines

  1. #include <libc.h>
  2. #include <sys/time.h>
  3. #define MAXRND 2147483649
  4. extern long random();
  5. extern void srandom();
  6.  
  7. int getRand(int MaxVal)
  8. {
  9. struct timeval tp;
  10. struct timezone tzp;
  11.  
  12.     gettimeofday(&tp, &tzp);
  13.     srandom((int) tp.tv_usec );
  14.     return(MaxVal * ((float) random()/(float) MAXRND) + 1 );
  15. }
  16.  
  17.